package me.exchange.com.annotation;

import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 枚举常量
 *
 * @Auther 张玉丰
 * @Date 2017/4/27
 */
public class Constant {
	/**
	 * 返回状态值
	 */
	public enum RESULT {
		/**
		 * 成功
		 */
		CODE_YES("0"),
		/**
		 * 失败
		 */
		CODE_NO("-1"),
		/**
		 * 失败msg
		 */
		MSG_YES("操作成功"),
		/**
		 * 失败msg
		 */
		MSG_NO("操作失败");
		private String value;

		private RESULT(String value) {
			this.value = value;
		}

		public String getValue() {
			return value;
		}
	}
	/**
	 * 上下线
	 */
	public enum MARKE {
		MARKE_UP("上线"),
		MARKE_DOWN("下线");

		private String value;

		private MARKE(String value) {
			this.value = value;
		}

		public String getValue() {
			return value;
		}
	}

	/**
	 * 文件类型
	 */
	public enum FILE_TYPE_ENUM {

		DOC_FILE_TYPE("doc文件", "application/msword"),
		BIN_FILE_TYPE("bin、exe、so、dll文件", "application/octet-stream"),
		PDF_FILE_TYPE("pdf文件", "'application/pdf'"),
		AI_FILE_TYPE("ai文件", "application/postscript"),
		XLS_FILE_TYPE("xls文件", "application/vnd.ms-excel"),
		PPT_FILE_TYPE("ppt文件", "application/vnd.ms-powerpoint"),
		DIR_FILE_TYPE("dir文件", "application/x-director"),
		JS_FILE_TYPE("js文件", "application/x-javascript"),
		SWF_FILE_TYPE("swf文件", "application/x-shockwave-flash"),
		XHT_FILE_TYPE("xht、xhtml文件", "application/xhtml+xml"),
		ZIP_FILE_TYPE("zip文件", "application/zip"),
		MP3_FILE_TYPE("mp3文件", "audio/mpeg"),
		RM_FILE_TYPE("rm文件", "x-pn-realaudio"),
		RPM_FILE_TYPE("rpm文件", "x-pn-realaudio-plugin"),
		WAV_FILE_TYPE("mav文件", "audio/x-wav"),
		BMP_FILE_TYPE("bmp文件", "image/bmp"),
		JPG_FILE_TYPE("jpeg、jpg文件", "image/jpeg"),
		PNG_FILE_TYPE("png文件", "image/png"),
		HTML_FILE_TYPE("htm、html文件", "text/html"),
		CSS_FILE_TYPE("css文件", "text/html"),
		XSL_FILE_TYPE("xsl、xml文件", "text/html"),
		TXT_FILE_TYPE("css文件", "text/plain"),
		MPG_FILE_TYPE("mpg、mpeg文件", "video/mpeg"),
		AVI_FILE_TYPE("avi文件", "video/x-msvideo"),
		MOVIE_FILE_TYPE("movie文件", "video/x-sgi-movie");

		private String fileType;
		private String description;

		public void setFileType(String fileType) {
			this.fileType = fileType;
		}

		public String getFileType() {
			return fileType;
		}

		public void setDescription(String description) {
			this.description = description;
		}

		public String getDescription() {
			return description;
		}

		private FILE_TYPE_ENUM(String fileType, String description) {
			this.fileType = fileType;
			this.description = description;
		}

		public static String getValue(String code) {
			for (FILE_TYPE_ENUM ele : values()) {
				if (ele.getDescription().equals(code)){
					return ele.getFileType();
				}
			}
			return code;
		}
	}

	/**
	 * @ClassName: DealWay
	 * @Description: 交易方式
	 */
	public enum DealWay {
		TAKER("taker", "市价"),
		MAKER("maker", "限价"),
		CANCEL("cancel", "系统撤单");

		public final String value;
		public final String label;

		DealWay(String value, String label) {
			this.value = value;
			this.label = label;
		}
	}
	/**
	 * @ClassName: OrderType
	 * @Description: Order类型
	 */
	public enum OrderType {
		MARKET("market", "市价"),
		LIMIT("limit", "限价");

		public final String value;
		public final String label;

		OrderType(String value, String label) {
			this.value = value;
			this.label = label;
		}
	}

	/**
	 * @ClassName: OrderState
	 * @Description: Order状态
	 * @author flying-cattle
	 * @date 2019年12月19日
	 */
	public enum OrderState {
		UNPAID(-1, "支付失败"),
		PAID(0, "已支付"),
		SOME_DEAL(1, "部分成交"),
		FINISH_DEAL(2, "全部成交"),
		CANCEL(3, "已撤销"),
		TO_UNDO(4, "撤销申请"),
		ERROR(5, "异常订单");

		public final int value;
		public final String label;

		OrderState(int value, String label) {
			this.value = value;
			this.label = label;
		}

		public static Optional<OrderState> of(int value) {
			return Arrays.stream(values()).filter(i -> i.value == value).findFirst();
		}
	}
}
